﻿@{
    Layout = "~/Areas/Mall/Views/Shared/_HomeLayout.cshtml";
}

<link rel="stylesheet" href="~/Areas/Mall/css/head.css">
<link rel="stylesheet" href="~/Areas/Mall/css/list.css">
<link rel="stylesheet" href="~/Areas/Mall/css/pagination.css" />
<style type="text/css">
    ul, li {
        list-style: none;
    }

    #wrapper {
        width: 900px;
        margin: 20px auto;
    }

    .data-container {
        margin-top: 5px;
    }

        .data-container ul {
            padding: 0;
            margin: 0;
        }

        .data-container li {
            margin-bottom: 5px;
            padding: 5px 10px;
            background: #eee;
            color: #666;
        }
</style>
<div class="store">
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
        <a href="@Url.Action("Index","Home")"><i></i><span>首页</span></a>
        <span> - 进货商城</span>
    </div>
    <div class="top">
        <button onclick="targetAdd()"><img src="~/Areas/Mall/image/add.png" />新增</button>
        <input id="txtKeyword" value="" />
        <button class="search" onclick="paging()"><img src="~/Areas/Mall/image/search.png" width="20" /></button>
    </div>

    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
        <tbody id="tbodyAddress">
            <tr class="odd_bg">
                <th width="10%">联系人</th>
                <th width="10%">电话</th>
                <th>收货地址</th>
                <th width="18%">管理操作</th>
            </tr>
        </tbody>
    </table>
    <div id="wrapper" class="page">
        <!--#488FCD-->
    </div>
</div>

<script type="text/javascript" src="~/Areas/Mall/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="~/Areas/Mall/js/pagination.min.js"></script>
<script type="text/javascript">
    //分页
    function paging() {
        $('#wrapper').pagination({
            dataSource: '@Url.Action("AddressList", "Address")',
            locator: 'Data.List',
            totalNumberLocator: function (response) {
                // you can return totalNumber by analyzing response content
                return response.Data.Count;
            },
            pageSize: 10,
            ajax: {
                beforeSend: function () {
                    //dataContainer.html('Loading data from flickr.com ...');
                },
                type: 'POST',
                data: {
                    keyword: $("#txtKeyword").val()
                }
            },
            callback: function (data, pagination) {
                $("#tbodyAddress").empty();
                var title = `
                <tr class="odd_bg">
                    <th width="10%">联系人</th>
                    <th width="10%">电话</th>
                    <th>收货地址</th>
                    <th width="18%">管理操作</th>
                </tr>`;
                $("#tbodyAddress").append(title);
                $(data).each(function (index, item) {
                    $("#tbodyAddress").append(`
                    <tr>
                        <td align="center">`+ item.RealName + `</td>
                        <td align="center">`+ item.Mobile + `</td>
                        <td align="center">`+ item.ProvinceName + `,` + item.CityName + `,` + item.SendAddress + `</td>

                        <td style="width: 18%; text-align: center">
                            <a href="@Url.Action("Edit","Address")?id=`+ item.Id +`">编辑</a>&nbsp;&nbsp;&nbsp;
                            <a onclick="delAddress(`+ item.Id +`)">删除</a>
                        </td>
                    </tr>`);
                });
            }
        });
    }

    //删除地址
    function delAddress(id) {
        $.ajax({
            type: "POST",
            url: '@Url.Action("DeleteAddress", "Address")',
            data: {
                "id": id
            },
            success: function (res) {
                if (res.Success) {
                    paging();
                } else {
                    alert(res.Message)
                }
            }
        });
    }

    //跳转
    function targetAdd() {
        window.location.href = '@Url.Action("Edit","Address")';//直接跳转
    }

    $(function () {
        paging();
    })

</script>